package com.aust.furniture.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.aust.furniture.entity.Classify;
import com.aust.furniture.mapper.ClassifyMapper;
import com.aust.furniture.service.IClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 家具分类service实现类
 */
@Service
public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> implements IClassifyService {

    @Autowired
    private ClassifyMapper classifyMapper;

    /**
     * 分页查询家具分类数据
     *
     * @param pageNum  第几页
     * @param pageSize 每页多少条数据
     * @param param    查询参数-家具分类名称
     * @return
     */
    @Override
    public IPage<Classify> selectClassifyPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Classify> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(param)){
            queryWrapper.like("dname",param);
        }
        Page<Classify> page = new Page<>(pageNum,pageSize);
        return classifyMapper.selectPage(page,queryWrapper);
    }

    /**
     * 新增一条家具分类信息
     *
     * @param classify
     */
    @Override
    public int addClassify(Classify classify) {
        return classifyMapper.insert(classify);
    }

    /**
     * 修改一条家具分类信息
     *
     * @param classify
     */
    @Override
    public int editClassify(Classify classify) {
        return classifyMapper.updateById(classify);
    }

    /**
     * 根据主键id查询一个家具分类对象
     *
     * @param id
     * @return
     */
    @Override
    public Classify queryClassifyById(Integer id) {
        return classifyMapper.selectById(id);
    }

    /**
     * 根据主键id删除一个家具分类对象
     *
     * @param id
     * @return
     */
    @Override
    public int delClassifyById(Integer id) {
        return classifyMapper.deleteById(id);
    }

    /**
     * 查询所有家具分类
     *
     * @return
     */
    @Override
    public List<Classify> queryClassifyList() {
        return classifyMapper.selectList(null);
    }
}
